//
//  XLBTabbarViewController.m
//  XLBUITabBarController_Example
//
//  Created by pinetree松松 on 2018/10/26.
//  Copyright © 2018年 acct<blob>=0xE88B8FE5AD90E79EBB. All rights reserved.

#import "XLBTabbarViewController.h"
#import "XLBTabBar.h"
#import "XLBViewController.h"

@interface XLBTabbarViewController ()

@end

@implementation XLBTabbarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
//    view.backgroundColor = [UIColor redColor];
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 49,49)];
    [btn setTitle:@"+" forState:UIControlStateNormal];
    btn.layer.cornerRadius = 49/2.0;
    btn.backgroundColor = [UIColor redColor];
    [btn addTarget:self action:@selector(btnCick) forControlEvents:UIControlEventTouchUpInside];
    XLBTabBar *tabbar = [[XLBTabBar alloc]initWithCenterView:btn];
//    XLBTabBar *tabbar = [[XLBTabBar alloc] init];
    self.view.backgroundColor = [UIColor whiteColor];
    [self setValue:tabbar forKey:@"tabBar"];
    
    
    [self setupUI];
    
}

- (void)btnCick{
    NSLog(@"btnCick");
    XLBViewController *vc = [[XLBViewController alloc] init];
    [self presentViewController:vc animated:YES completion:^{
        
    }];
}
-(void)setupUI
{
    // 通过appearance统一设置UITabbarItem的文字属性
    NSMutableDictionary * attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:12.0];  // 设置文字大小
    attrs[NSForegroundColorAttributeName] = [UIColor grayColor];  // 设置文字的前景色
    
    NSMutableDictionary * selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSFontAttributeName] = attrs[NSFontAttributeName];
    selectedAttrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    
    UITabBarItem * item = [UITabBarItem appearance];  // 设置appearance
    [item setTitleTextAttributes:attrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
    
    // 添加子控制器
    UIViewController * VC01 = [[UIViewController alloc]init];
    // 设置标题
    VC01.tabBarItem.title = @"精华";
    // 设置默认图片
    VC01.tabBarItem.image = [UIImage imageNamed:@"tabBar_essence_icon"];
    //设置选中图片
    VC01.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_essence_click_icon"];
    
    
    [VC01.tabBarItem setTitleTextAttributes:attrs forState:UIControlStateNormal];
    
    VC01.view.backgroundColor = [UIColor yellowColor];
    [self addChildViewController:VC01];
    
    UIViewController * VC02 = [[UIViewController alloc]init];
    VC02.tabBarItem.title = @"新帖";
    VC02.tabBarItem.image = [UIImage imageNamed:@"tabBar_new_icon"];
    VC02.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_new_click_icon"];
    VC02.view.backgroundColor = [UIColor redColor];
    [self addChildViewController:VC02];
    
    UIViewController * VC03 = [[UIViewController alloc]init];
    VC03.tabBarItem.title = @"关注";
    VC03.tabBarItem.image = [UIImage imageNamed:@"tabBar_friendTrends_icon"];
    VC03.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_friendTrends_click_icon"];
    VC03.view.backgroundColor = [UIColor blueColor];
    [self addChildViewController:VC03];
    
    UIViewController * VC04 = [[UIViewController alloc]init];
    VC04.tabBarItem.title = @"我";
    VC04.tabBarItem.image = [UIImage imageNamed:@"tabBar_me_icon"];
    VC04.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_me_click_icon"];
    VC04.view.backgroundColor = [UIColor greenColor];
    VC04.title = @"我";
    [self addChildViewController:[[UINavigationController alloc]initWithRootViewController:VC04]];

}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
